﻿using System.Diagnostics;
using System.Xml.Linq;

namespace Bing
{   // TODO: Documentation Error: http://msdn.microsoft.com/en-us/library/dd251010.aspx, not used in the sample application
    /// <summary>
    /// Contains the title and URL for a search that Bing suggests is related to the query terms for a request to the News <see cref="ApiHelper.SourceType"/>.
    /// </summary>
    [DebuggerDisplay("Title: {Title} - {Url}")]
    public class NewsRelatedSearch
    {
        /// <summary>
        /// Gets or sets the title for a search that Bing suggests is related to the query terms for a request.
        /// </summary>
        /// <value>The title for a search that Bing suggests is related to the query terms for a request.</value>
        public string Title { get; set; }

        /// <summary>
        /// Gets or sets the URL of this related search.
        /// </summary>
        /// <value>The URL of this related search.</value>
        public string Url { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="NewsRelatedSearch"/> class.
        /// </summary>
        public NewsRelatedSearch()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="NewsRelatedSearch"/> class.
        /// </summary>
        /// <param name="element">The element.</param>
        public NewsRelatedSearch(XNode element)
        {
            if (element == null) return;

            Title = ApiHelper.GetElementValueOrDefault<string>(element, "Title", ApiHelper.NewsNs);
            Url = ApiHelper.GetElementValueOrDefault<string>(element, "Url", ApiHelper.NewsNs);
        }
    }
}
